package cn.sdormitory.controller;


import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.school.service.SchoolPatrolHandleService;
import cn.sdormitory.school.vo.SchoolPatrolVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("app/dutyHandle")
public class AppDutyHandleController {

    @Autowired
    SchoolPatrolHandleService schoolPatrolHandleService;

    @GetMapping("/find/todoList/{chargeTeacherId}")
    public CommonResult<List<SchoolPatrolVo>> findToDoListByTeacherId(@PathVariable("chargeTeacherId") Long chargeTeacherId){
        List<SchoolPatrolVo>list = schoolPatrolHandleService.findToDoListByTeacherId(chargeTeacherId);
        return CommonResult.success(list);
    }

    @GetMapping("/find/todoListCount/{chargeTeacherId}")
    public CommonResult<Integer> findToDoListCountByTeacherId(@PathVariable("chargeTeacherId") Long chargeTeacherId){
        Integer count = schoolPatrolHandleService.findToDoListCountByTeacherId(chargeTeacherId);
        return CommonResult.success(count);
    }

    @PutMapping("/update/status")
    public CommonResult updatePatrolHandleStatus(@RequestBody Map<String,Object> params){
        int num = schoolPatrolHandleService.updatePatrolHandleStatus(params);
        if(num > 0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @PostMapping("/findList")
    public CommonResult findList(@RequestBody Map<String,Object> params){
        List<Map<String, Object>> allList = schoolPatrolHandleService.findList(params);
        return CommonResult.success(allList);
    }
}
